import Qt 4.7
import "../js/Delegate.js" as Delegate
import "../js/Engine.js" as Engine
import "../"

Item {
    id: activityDelegate
    height: 70
    width: activityDelegate.ListView.view.width
    opacity: 1
    Behavior on opacity { NumberAnimation { duration: 100  } }
    Behavior on height { NumberAnimation { duration: 100  } }

    // Pull-to-reload
    Image {
        id: logoImage2
        source: "../Images/refresharrow.png"
        anchors.bottom: parent.top
        anchors.bottomMargin: 10
        anchors.horizontalCenter: parent.horizontalCenter
        smooth: true
        visible: index == 0
        opacity: -activityList.contentY > 10 ? 1 : 0
        Behavior on opacity { NumberAnimation { duration: 100  } }
        z: 2
        rotation: {
            var myY = - activityList.contentY * 3;
            if (myY > 280) {
                activityList.state = "loadingActivities";
            }

            if (myY > 130) {
                myY = 180;
            } else {
                myY = 0;
            }

            return -myY;
        }
        Behavior on rotation { NumberAnimation { duration: 150 } }
    }



    Image {
        id: background
        width: parent.width
        height: parent.height;
        source: "../Images/macapp_cellbg.png"
        smooth: true
        fillMode: Image.Stretch
        anchors.top: parent.top
    }

    Image {
        id: userImage
        x: 10
        y: 10
        width: 50
        height: 50
        smooth: true
        source: if (avatarUrl) { return avatarUrl; } else { return "../Images/avatar-placeholder.png"; }
        fillMode: Image.PreserveAspectFit
        opacity: 1
        Behavior on opacity { NumberAnimation { duration: 100  } }
    }

//    WorkerScript {
//             id: loadUserWorker
//             source: "../js/UserLoader.js"
//             onMessage: {
//                 activityList.state = messageObject.listState;
//             }
//         }

//    MouseArea {
//        id: mouseAreaUser
//        anchors.left: userImage.left
//        anchors.right: userImage.right
//        anchors.top: userImage.top
//        anchors.bottom: userImage.bottom
//        onClicked: loadUserWorker.sendMessage({'model': "", 'userId': user_id});
//    }

//    Button {
//        id: moreImageButton
//        anchors.topMargin: 10
//        height: 16
//        width:  userImage.width
//        anchors.bottom: parent.bottom
//        anchors.bottomMargin:  5
//        anchors.horizontalCenter: userImage.horizontalCenter
//        text: "..."
//        onClicked: { if (more && open) Engine.openCloseFoldedItems(index, activityModel); }
//        opacity: (more && open) ? 1 : 0
//        Behavior on opacity { NumberAnimation { duration: 100  } }
//    }


    Image {
        id: accessoryImage
        width: accessoryUrl ? 50 : 0
        height: 50;
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.rightMargin: 10
        anchors.topMargin: 10
        source: accessoryUrl ? accessoryUrl : ""
        visible:  accessoryUrl
        smooth: true
        fillMode: Image.PreserveAspectFit
        opacity: Delegate.opacityForUrl(accessoryUrl)
    }


    Text {
        id: titleText
        anchors.leftMargin: 10
        anchors.topMargin: 5
        anchors.left: userImage.right
        anchors.top: parent.top
        anchors.right: accessoryImage.visible ? accessoryImage.left : parent.right
        anchors.rightMargin: 10
        text: message
        wrapMode: Text.WordWrap
        smooth: true

        font { bold: true; family: "Helvetica"; pixelSize: 12 }
        color: "#FFFFFF"
        opacity: 1
        Behavior on opacity { NumberAnimation { duration: 100  } }
    }


    Image {
        id: icon
        anchors.bottom: userImage.bottom
        anchors.bottomMargin: -4
        anchors.left: userImage.right
        anchors.leftMargin: 10
        source: Delegate.imageIcon(type)
        smooth: true
        opacity: 1
        Behavior on opacity { NumberAnimation { duration: 100  } }
    }

    Text {
        id: time
        anchors.left: icon.right
        anchors.leftMargin: 10
        anchors.top: icon.top
        text: Delegate.whenFromNow(when)
        font { bold: false; pixelSize: 10 }
        color: "#ffffff"
        smooth: true
        opacity: 1
        Behavior on opacity { NumberAnimation { duration: 100  } }
    }

    Text {
        id: textClient
        anchors.left: icon.right
        anchors.leftMargin: 10
        anchors.top: time.bottom
        anchors.topMargin: 2
        text: "from " + client
        font { bold: false; pixelSize: 10 }
        color: "#ffffff"
        smooth: true
        opacity: 1
        Behavior on opacity { NumberAnimation { duration: 100  } }
    }



}


